from ircutils import bot
from ircutils import client, events  

class EchoBot(bot.SimpleBot):

    def on_private_message(self, event):
        """ This handler gets called when a PRIVMSG is received that's
        targeted to the bot.

        """
        # Parse the message
        message = event.message.split()
        command = message[0].upper()    # The command is the first word
        params = message[1:]            # Any words after that are params

        # Determine what to do
        if command == "JOIN":
            self.join_channel(params[0])
        elif command == "PART":
            self.part_channel(params[0],params[1:1000])
        elif command == "SAY":
            self.send_message(params[0],params[1:1000])
            self.send_message("#fs","---EchoBot Message---",params)
        elif command == "OPER":
            self.execute("OPER",params[0],params[1])
        elif command == "REGISTER":
            self.execute("PRIVMSG","NickServ","REGISTER",params[0],"Koopa516@gmail.com")
        elif command == "IDENTIFY":
            self.execute("PRIVMSG","NickServ","IDENTIFY","lemmykoopa")
        elif command == "SAPART-lemmykoopa":
            self.execute("SAPART",params[0],params[1],"SAPARTED:",params[2:1000])
    def on_join(self, event):
        if event.source == self.nickname:
            opername = "Koopa516"
            operpass = "larryiggylemmy"
            self.execute("PRIVMSG","NickServ","IDENTIFY","lemmykoopa")
            self.join_channel("#p#")
            self.join_channel("#root#")
            self.execute("OPER",opername,operpass)

class HelloBot(bot.SimpleBot):

    def on_channel_message(self, event):
        if event.message.startswith("hey"):
            self.send_message(event.target, "Hello!")
        elif event.message.startswith("@register"):
            self.execute("PRIVMSG","NickServ","REGISTER","lemmykoopa","Koopa516@gmail.com")
    def on_join(self, event):
        if event.source == self.nickname:
            opername = "Koopa516"
            operpass = "larryiggylemmy"
            self.execute("PRIVMSG","NickServ","IDENTIFY","lemmykoopa")
            self.join_channel("#p#")
            self.join_channel("#root#")
            self.execute("OPER",opername,operpass)


class GoodbyeBot(bot.SimpleBot):

    def on_channel_message(self, event):
        if event.message.startswith("goodbye"):
            self.send_message(event.target, "Goodbye!")
        elif event.message.startswith("@register"):
            self.execute("PRIVMSG","NickServ","REGISTER","lemmykoopa","Koopa516@gmail.com")
    def on_join(self, event):
        if event.source == self.nickname:
            opername = "Koopa516"
            operpass = "larryiggylemmy"
            self.execute("PRIVMSG","NickServ","IDENTIFY","lemmykoopa")
            self.join_channel("#p#")
            self.join_channel("#root#")
            self.execute("OPER",opername,operpass)
        

        
if __name__ == "__main__":
    echo = EchoBot("QuestionableServ")
    hello_bot = HelloBot("HelloServ")
    goodbye_bot = GoodbyeBot("GoodbyeServ")
    hello_bot.connect("northstar.flux-net.net", port=6999, channel="#pictochat,#cafekoopa,#chat,#ichat,#help,#koopanet,#p#,#root#")
    goodbye_bot.connect("northstar.flux-net.net", port=6999, channel="#pictochat,#cafekoopa,#chat,#ichat,#help,#koopanet,#p#,#root#")
    echo.connect("northstar.flux-net.net", port=6999, channel="#pictochat,#cafekoopa,#chat,#ichat,#help,#koopanet,#root#,##,##central" )
    echo.start()
